/* $Id:game_window.h jjs $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/
#ifndef GAME_WINDOW_H
#define GAME_WINDOW_H

#include <gtkmm.h>
#include <libglademm.h>
#include <gtkmm/drawingarea.h>
#include "../general/channel.h"

#define slen_x 7
#define slen_y 5

class game_window;

class draw_area : public Gtk::DrawingArea {
  public:
    draw_area(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade) :
      Gtk::DrawingArea(cobject), m_refGlade(refGlade) {}
    virtual ~draw_area() {};
    game_window *curr;

  protected:
	Glib::RefPtr<Gdk::Pixmap> background;
	void bg_image(string name, int x, int y);
	void calc_background();
	void move_background(int dir);
    void image(string name, int x, int y);
    virtual bool on_expose_event(GdkEventExpose* event);
    Glib::RefPtr<Gnome::Glade::Xml> m_refGlade;
};

class tile {
  public:
    tile() {
        terrain=0;
        fields=0;
        name="";
        citysize=0;
        wallsize=0;
        wall=0;
        moat=0;
    }
    unsigned int terrain : 4;
    unsigned char add[8];
    unsigned int fields: 8;
    std::string name;
    unsigned int citysize: 8;
    unsigned int castlesize: 8;
    unsigned int wallsize: 8;
    unsigned int wall: 2;
    unsigned int moat: 2;
};

class game_window : public Gtk::Window {
  public:
	game_window(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> refGlade); ///< Window
	virtual ~game_window(); ///< Remove window data
  private:
    tile map[slen_x*6+1][slen_y*6+1];
    int cx; ///< current x tile postion
    int cy; ///< current y tile position
    int sx; ///< current x pixel position
    int sy; ///< current y pixel position
    void set_map(int x,int y,tile t);
    tile get_map(int x,int y);
  protected:
	Glib::RefPtr<Gnome::Glade::Xml> m_refGlade;
	draw_area* area;
	Gtk::TreeView* game_tree;
	void file_handler(std::string f);
	void game_handler(channel *ch);
    channel *ch;

    /// Definition of the columns on the screen
	struct ModelColumns : public Gtk::TreeModelColumnRecord {
       	Gtk::TreeModelColumn<Glib::ustring> name;
    	Gtk::TreeModelColumn<Glib::ustring> descr;
        Gtk::TreeModelColumn<int> item_nr;
    	ModelColumns()
		{
			add(name); add(descr);
			add(item_nr);
		}
	};
	const ModelColumns cols;
};

#endif //GAME_WINDOW_H

